import { controller, httpGet as Get,httpPost as Post } from "inversify-express-utils";
import { UserService } from "./services";
import { inject } from "inversify";
import type { Request, Response } from 'express'
import { JWT } from "../jwt";

@controller("/user")
export class User {
  constructor (
    @inject(UserService) private readonly userService: UserService) {
    
  }

  @Get("/index",JWT.middleware())
  public async getIndex (req: Request, res: Response) {
    console.log(req.query);
    // 需要扩展 Request 类型以包含 user 属性
    console.log((req as any).user);
    
    const result = await this.userService.getList()
    res.send(result)
  }

  @Post('/create')
  public async createUser (req: Request, res: Response) {
    console.log(req.body);
    
    const result = await this.userService.createUser(req.body)
    res.send(result)
  }
}